package realQuestion.min;


    import java.util.Scanner;

import  java.util.*;
    // 注意类名必须为 Main, 不要有任何 package xxx 信息
    public class Main3 {
        static  HashMap<Integer,Integer> map=new HashMap<>();
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);

            String s=in.next();
            String []  s1=s.split(";");
            int pairs=  s1.length;
            int[]  x=new int[pairs];


            for(int i=0;i<pairs;i++){
                String s2=s1[i];
                String[] s3= s2.split(",");
                int xx=Integer.valueOf(s3[0]);
                x[i]=xx;
                int yy=Integer.valueOf(s3[1]);
                map.put(xx,yy);
            }


            int longest=0;
            for(int i=0;i<pairs;i++){
                int cur=x[i];
                int nowlong=0;
                while(map.containsKey(cur)){
                    nowlong++;
                    cur=map.get(cur);

                }
                longest=Math.max(longest,nowlong);


            }

            System.out.println(longest+1);



        }
    }

